# coding=utf-8
from twisted.internet import reactor

from game.util.RandomUtil import get_next_card

GOLD_POOL = 0  # 奖池金额
NEXT_CARD = []  # 测试用设定下局开出的点数
ONE_ROUND_TIME = 5  # 一局间隔时间
IS_START = False


class WuXingHongHui(object):
    def __init__(self, gold_pool=0, next_card=[], one_round_time=3, is_start=False):
        """
        游戏初始化
        :param gold_pool: 奖池
        :param next_card: 下一张牌色
        :param one_round_time: 一局游戏时间
        :param is_start: 是否已经开始游戏
        """
        self.gold_pool = gold_pool
        self.next_card = next_card
        self.one_round_time = one_round_time
        self.is_start = is_start
        self.send_all = None
        self.send_one = None

    def init_send_util(self, send_one, send_all):
        """
        初始化推送方法
        :param send_one: 单推
        :param send_all: 全推
        :return:
        """
        self.send_all = send_all
        self.send_one = send_one

    def test_print(self, say):
        print say
        self.get_lottery_result()

    def get_lottery_result(self):
        # TODO 查看奖池状态, 根据奖池 设置开奖策略
        r = get_next_card(self.gold_pool)
        if self.next_card:
            r = self.next_card.pop()
        print r
        # TODO 广播中间结果
        self.send_all(100, r)
        if self.is_start:
            reactor.callLater(self.one_round_time, self.get_lottery_result)


if __name__ == "__main__":
    w = WuXingHongHui()
    reactor.callWhenRunning(w.test_print, say="game start!!!")
    reactor.run()
